#import "GSommet.h"

template <class G, class S, class A>
GSommet<G, S, A>::GSommet(string nom, G *graphe){
	listeAretes = new vector<A *>();
	this->nom = nom;
	this->graphe = graphe;

}

template <class G, class S, class A>
GSommet<G, S, A>::~GSommet(){

}

template <class G, class S, class A>
void GSommet<G, S, A>::deleteSommet(){
	while((int)listeAretes->size()!=0){
		A * a = listeAretes->back();
		listeAretes->pop_back();
		a->deleteArete();
		delete a;
	}
	graphe->removeSommet(dynamic_cast<S *>(this));
	//delete this;
}

//########################################################################

template <class G, class S, class A>
string GSommet<G, S, A>::getNom(){
	return nom;
}

template <class G, class S, class A>
string GSommet<G, S, A>::toStringComplet(){
	string s = toString();
	s += "\n#"+graphe->toString();
	for(int i = 0; i< (int)listeAretes->size(); i++){
		s += "\n-"+listeAretes->at(i)->toString();
	}
	return s;
}

//########################################################################

template <class G, class S, class A>
G * GSommet<G, S, A>::getGraphe(){
	return graphe;
}

//########################################################################

template <class G, class S, class A>
void GSommet<G, S, A>::addArete(A *arete){
	listeAretes->push_back(arete);
}

template <class G, class S, class A>
void GSommet<G, S, A>::removeArete(A *arete){
	for (int i=0;i<(int)listeAretes->size(); i++){
		if (listeAretes->at(i)==arete){
			listeAretes->erase(listeAretes->begin()+i);
			break;
		}
	}
}

template <class G, class S, class A>
A * GSommet<G, S, A>::getArete(int i){
	if (i>=0 && i<(int)listeAretes->size())	return listeAretes->at(i);
	else return NULL;
}
